package com.hlf.modules.h5.controller;

import com.hlf.common.constants.Constants;
import com.hlf.common.utils.ReturnResult;
import com.hlf.modules.h5.annotation.LoginUser;
import com.hlf.modules.merchant.goods.entity.Goods;
import com.hlf.modules.merchant.goods.entity.GoodsType;
import com.hlf.modules.merchant.goods.service.GoodsService;
import com.hlf.modules.merchant.goods.service.GoodsTypeService;
import com.hlf.modules.wechat.model.Customer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/5.
 */

@Api("H5商品接口")
@RestController
@RequestMapping("/h5/goods/")
public class H5GoodsController {

    @Autowired
    private GoodsService goodsService;
    @Autowired
    private GoodsTypeService goodsTypeService;

    /**
     * h5茶位费价格
     */
    @ApiOperation(value = "茶位费价格", notes = "茶位费价格")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "token", value = "token", required = true),
    })
    @GetMapping(value = "/teaPrice")
    public ReturnResult teaPrice(@LoginUser Customer customer){
        Goods goods = goodsService.queryTeaForStoreId(customer.getSpendStoreId());
        return  ReturnResult.ok().put(Constants.DEFAULT_RESULT_NAME,goods);
    }

    /**
     * 根据商品类型分类后的 商品列表
     */
    @GetMapping("list")
    @ApiOperation(value = "h5根据商品类型分类后的 商品列表", notes = "h5根据商品类型分类后的 商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "token", value = "token", required = true)
    })
    public ReturnResult list(@LoginUser Customer customer) {

        List<GoodsType> goodsTypes = goodsTypeService.batchQueryListStoreId(customer.getSpendStoreId());
        Map<String, Object> map = new HashMap<>();
        map.put(Constants.DEFAULT_RESULT_NAME, goodsTypes);
        return ReturnResult.ok(map);
    }

}
